﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Comm;
using VK.Casemeet.Members;

namespace VK.Casemeet.Web.Front
{
    public partial class FindPassEdit : System.Web.UI.Page
    {
        public string strMessage = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void butSubmit_Click(object sender, EventArgs e)
        {
            if (txtEmail.Text.Length == 0)
            {
                strMessage += "<p>帐号不能为空!</p>";
            }
            else
            {
                if (!RegexStr.CheckEmail(txtEmail.Text))
                {
                    strMessage += "<p>帐号只能为邮箱格式!</p>";
                }
            }
            if (txtPass.Text.Length == 0)
            {
                strMessage += "<p>密　码不能为空!</p>";
            }
            else
            {
                if (txtPass.Text.Length < 4 || txtPass.Text.Length > 20)
                {
                    strMessage += "<p>密　码(4-20)位字符!</p>";
                }
                else
                {
                    if (!string.Equals(txtPass.Text, txtPassCheck.Text))
                    {
                        strMessage += "<p>两次密码输入要相同!</p>";
                    }
                }
            }

            if (!string.IsNullOrEmpty(strMessage))
            {
                strMessage = "<dd id='vcodeMsg' class='loginMsg'>" + strMessage;
                strMessage = strMessage + "</dd>";
                return;
            }

            string code = Util.GetRouteDataString("code");
            MemberEntity member = MemberBLL.GetMemberByValidateCode(code);

            if (txtEmail.Text == member.Email)
            {
                member.Password = DES.Encrypt(txtPass.Text, CS.MemberPassKey);
                if (MemberBLL.UpdateMember(member) > 0)
                {
                    Response.Redirect("/FindPassComplete.html");
                }
                else
                {
                    strMessage = "新密码设置失败！";
                }
            }
        }
    }
}